package com.blue.controller.workflow;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.github.yulichang.query.MPJQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blue.common.utils.QueryWrapperUtils;
import org.springframework.web.bind.annotation.*;
import com.blue.common.utils.ConvertUtils;
import com.blue.po.workflow.NodeConditionPO;
import com.blue.dto.workflow.NodeConditionDTO;
import com.blue.service.workflow.INodeConditionService;
import com.blue.common.entity.ResponseResult;

import java.util.List;


/**
 * 流程节点条件表
 *
 * @author nanjie.chen
 * @email 15696471158@163.com
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/workflow/nodeCondition")
@Tag(name = "流程节点条件表")
public class NodeConditionController {
    @Autowired
    private INodeConditionService nodeConditionService;

    @GetMapping("/pageList")
    @Operation(summary = "列表查询")
    public ResponseResult<?> list(NodeConditionDTO requestDTO,
                                  @RequestParam(value = "pageSize", defaultValue = "10") long pageSize,
                                  @RequestParam(value = "pageNum", defaultValue = "1") long pageNum) {
        NodeConditionPO nodeConditionPO = ConvertUtils.convert(NodeConditionPO.class, requestDTO);
        MPJQueryWrapper<NodeConditionPO> queryWrapper = QueryWrapperUtils.initQueryWrapper(nodeConditionPO);
        Page<NodeConditionPO> page = new Page<>(pageNum, pageSize);
        Page<NodeConditionPO> pageResult = nodeConditionService.page(page, queryWrapper);
        return ResponseResult.okResult(pageResult);
    }

    @PostMapping("/add")
    @Operation(summary = "新增")
    public ResponseResult<?> add(@RequestBody NodeConditionDTO requestDTO) {
        NodeConditionPO nodeConditionPO = ConvertUtils.convert(NodeConditionPO.class, requestDTO);
        nodeConditionService.save(nodeConditionPO);
        return ResponseResult.okResult();
    }

    @PostMapping("/edit")
    @Operation(summary = "修改")
    public ResponseResult<?> edit(@RequestBody NodeConditionDTO requestDTO) {
        NodeConditionPO nodeConditionPO = ConvertUtils.convert(NodeConditionPO.class, requestDTO);
        nodeConditionService.updateById(nodeConditionPO);
        return ResponseResult.okResult();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除")
    public ResponseResult<?> delete(@RequestBody List<String> ids) {
        nodeConditionService.removeBatchByIds(ids);
        return ResponseResult.okResult();
    }

    @PostMapping("/queryById")
    @Operation(summary = "通过ID查询")
    public ResponseResult<?> queryById(@RequestBody NodeConditionDTO requestDTO) {
        NodeConditionPO nodeConditionPO = nodeConditionService.getById(requestDTO.getId());
        return ResponseResult.okResult(nodeConditionPO);
    }
}
